<template>
  <el-icon class="collapse-icon" @click="changeCollapse">
    <component :is="isCollapse ? 'Expand' : 'Fold'"></component>
  </el-icon>
</template>

<script setup lang="ts">
import { computed } from 'vue';
import actions from '../../stores/globalState';
import { useGlobalStore } from '../../store/modules/global';

const globalStore = useGlobalStore();
const isCollapse = computed(() => globalStore.isCollapse);

const changeCollapse = () => {
  const newValue = !isCollapse.value;
  // 同步更新 Pinia 和 Qiankun 全局状态
  globalStore.setGlobalState("isCollapse", newValue);
  actions.setGlobalState({ isCollapse: newValue });
};
</script>

<script lang="ts">
export default {
  name: 'CollapseIcon'
};
</script>

<style scoped lang="scss">
/* Ant Design Pro 标准折叠图标样式 */
.collapse-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px; // Ant Design Pro 标准触摸区域
  height: 36px;
  margin-right: 16px; // Ant Design Pro 标准间距
  font-size: 18px; // Ant Design Pro 图标大小
  cursor: pointer;
  color: rgba(0, 0, 0, 0.65); // Ant Design Pro 常规文字色
  border-radius: 2px; // Ant Design Pro 小圆角
  transition: all 0.3s cubic-bezier(0.645, 0.045, 0.355, 1); // Ant Design 标准缓动
  user-select: none;
  
  &:hover {
    color: var(--el-color-primary); // Hover 时显示主题色
    background-color: rgba(0, 0, 0, 0.04); // Ant Design Pro hover 背景
    transform: scale(1.08); // 轻微放大效果
  }
  
  &:active {
    transform: scale(0.95); // 点击反馈
  }
}

/* 暗黑模式适配 */
[data-theme='dark'] {
  .collapse-icon {
    color: rgba(255, 255, 255, 0.65);
  
  &:hover {
    color: var(--el-color-primary);
      background-color: rgba(255, 255, 255, 0.08);
    }
  }
}
</style>
